// index.js
// 导入request请求工具类
import {
    getBaseUrl,
    requestUtil
} from '../../utils/requestUtil.js';
import regeneratorRuntime from '../../lib/runtime/runtime';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        //轮播图数组
        swiperList: [],
        baseUrl: 'http://localhost:8080/springbootm7qt4/',
        //食品大类数组
        bigTypeList: [],
        bigTypeList_row1: [],
        hotProductList: [],
        hotProductLists: [],
        topRecommendOfUserId: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        // const baseUrl=getBaseUrl();
        //      this.setData({
        //        baseUrl
        //      })
        //发送异步请求获取后端数据
        // wx.request({
        //   url: 'http://localhost:8080/product/findSwiper',
        //   method:"GET",
        //   success:(result)=>{
        //     console.log(result)
        //     this.setData({
        //       swiperList:result.data.message
        //     })
        //     wx.request({
        //       url: 'url',
        //     })
        //   }
        // })
        this.getSwiperList();
        this.getHotProductList();
        this.topRecommendOfUserId();
        this.fuwu()
    },
    //食品大类点击事件跳转食品分类
    handleTypeJump(e) {
        const {
            index
        } = e.currentTarget.dataset;
        const app = getApp();
        app.globalData.index = index;
        wx.switchTab({
            url: '/pages/category/index'
        })
    },


    async getSwiperList() {
        // requestUtil({url: '/product/findSwiper',method:"GET"})
        //   .then(result=>{
        //     const baseUrl=getBaseUrl();
        //     this.setData({
        //       swiperList:result.message,
        //       baseUrl
        //     })
        //   })
        const result = await requestUtil({
            url: '/config/list',
            method: "GET"
        });
        this.setData({
            swiperList: result.data.list,
        })
    },
    // 获取热卖食品
    async getHotProductList() {
        const result = await requestUtil({
            url: '/fuwuleixing/list',
            method: "GET"
        });
        this.setData({
            hotProductList: result.data.list,
        })
    },
    jump(e) {
        const {
            index
        } = e.currentTarget.dataset;
        console.log(index, 'dndnd')
        wx.setStorageSync('currentIndex', index)
        wx.switchTab({
            url: '/pages/category/index',
        })
    },

    // 获取热卖食品
    async topRecommendOfUserId() {
        const result = await requestUtil({
            url: '/collect/topRecommendOfUserId',
            method: "GET"
        });
        this.setData({
            topRecommendOfUserId: result.data.list,
        })
    },

    async fuwu() {
        const result = await requestUtil({
            url: '/fuwuxinxi/list',
            method: "GET"
        });
        this.setData({
            hotProductLists: result.data.list,
        })
    },


})